import { Segmented, Card, Tag, Col, Row, Checkbox, Button, message, Input } from 'myselfantd';
import styles from './index.module.scss';
// import { allocateDevice, allocateMaps } from '@/services/api/enterprise';
import { useEffect, useState, memo, useCallback, useMemo } from 'react';
import MapContent from './MapContent';
import MachineContent from './MachineContent';
export default memo(({ params, close, onFinish }: any) => {
  const [selectData, setSelectData] = useState([] as any);
  enum TYPE {
    地图资源,
    农机资源,
  }
  const [type, setType] = useState(0);
  const handleChange = (val: any) => {
    setType(val);
  };
  const handleSave = async () => {
    // if (!selectData.length) {
    //   return message.info('请选择数据');
    // }
    // if (1 === type) {
    //   let res = await allocateDevice({ machineIds: selectData, id: params.id });
    //   if (res.message === 'success') {
    //     message.success('保存成功');
    //     onFinish?.();
    //   }
    // } else {
    //   let res = await allocateMaps({ farmCodes: selectData, id: params.id });
    //   if (res.message === 'success') {
    //     message.success('保存成功');
    //     onFinish?.();
    //   }
    // }
  };

  return (
    <div className={styles.resources}>
      <Segmented.Tabs
        onChange={useCallback(handleChange, [])}
        item={useMemo(
          () => [
            {
              label: TYPE[0],
              value: 0,
              content: <MapContent params={params} onSelectDataChange={setSelectData} />,
            },
            {
              label: TYPE[1],
              value: 1,
              content: <MachineContent params={params} onSelectDataChange={setSelectData} />,
            },
          ],
          [],
        )}
      />
      <Row>
        <Col span={12}>
          <Button
            block
            size="large"
            htmlType="button"
            // onClick={onReset}
            style={{ color: '#A5A5A5' }}
            onClick={() => close()}
          >
            取消
          </Button>
        </Col>
        <Col span={12}>
          <Button
            block
            size="large"
            htmlType="submit"
            style={{ color: '#4890FF' }}
            onClick={handleSave}
          >
            保存
          </Button>
        </Col>
      </Row>
    </div>
  );
});
